package com.imooc.flink.hudi;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.types.Row;

/**
 * @author: Chen Yixing
 * @since: 2023/10/31 19:31:54
 * @description:
 */
public class HudiSQLApp {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
        tableEnv.executeSql("CREATE TABLE t1(\n" +
                "  uuid VARCHAR(20) PRIMARY KEY NOT ENFORCED,\n" +
                "  name VARCHAR(10),\n" +
                "  age INT,\n" +
                "  ts TIMESTAMP(3),\n" +
                "  `partition` VARCHAR(20)\n" +
                ")\n" +
                "PARTITIONED BY (`partition`)\n" +
                "WITH (\n" +
                "  'connector' = 'hudi',\n" +
                "  'path' = 'hdfs://192.168.197.131:8020/user/hudi/warehouse/hudi_db/t1',\n" +
                "  'table.type' = 'MERGE_ON_READ',\n" +
                "  'precombine.field' = 'ts'\n" +
                ")");
        Table table = tableEnv.sqlQuery("select * from t1");
        tableEnv.toRetractStream(table, Row.class).filter(x -> x.f0).print("row:");

        env.execute("HudiSQLApp");
    }
}
